﻿package com.tudou.home.common.button
{
    import com.tudou.home.common.utils.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.text.*;

    public class IconText extends Sprite
    {
        protected var totalWidth:Number;
        protected var titleText:TextField;
        protected const BETWEEN:Number = 2;
        protected var iconDisplay:DisplayObject;

        public function IconText(param1:Number)
        {
            this.totalWidth = param1;
            titleText = TextFieldUtil.getTextField();
            addChild(titleText);
            return;
        }// end function

        public function set textFormat(param1:TextFormat) : void
        {
            titleText.defaultTextFormat = param1;
            titleText.setTextFormat(param1);
            return;
        }// end function

        public function set title(param1:String) : void
        {
            titleText.text = param1;
            return;
        }// end function

        public function set icon(param1:DisplayObject) : void
        {
            if (iconDisplay)
            {
                param1.width = iconDisplay.width;
                param1.height = iconDisplay.height;
                removeChild(param1);
            }
            iconDisplay = param1;
            addChild(iconDisplay);
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_1:Number = NaN;
            var _loc_2:Number = NaN;
            var _loc_3:Number = NaN;
            if (iconDisplay)
            {
                _loc_2 = iconDisplay.width + BETWEEN;
                titleText.x = _loc_2;
                _loc_1 = Math.max(totalWidth - _loc_2, 0);
                titleText.text = CutString.cutString(titleText.text, _loc_1, titleText);
                LayoutUtil.layout([iconDisplay, titleText], false, true);
            }
            else
            {
                titleText.x = 0;
                titleText.text = CutString.cutString(titleText.text, totalWidth, titleText);
                titleText.y = 0;
            }
            return;
        }// end function

        public function setIconSize(param1:Number, param2:Number) : void
        {
            if (iconDisplay)
            {
                iconDisplay.width = param1;
                iconDisplay.height = param2;
            }
            return;
        }// end function

    }
}
